package com.tianji.learning.mq;

import com.tianji.learning.mq.message.SingMessage;
import com.tianji.learning.service.IPointsRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import static com.tianji.common.constants.MqConstants.Exchange.LEARNING_EXCHANGE;
import static com.tianji.common.constants.MqConstants.Key.SIGN_IN;
import static com.tianji.common.constants.MqConstants.Key.WRITE_REPLY;
import static com.tianji.learning.enums.PointsRecordType.QA;
import static com.tianji.learning.enums.PointsRecordType.SIGN;

@Component
@RequiredArgsConstructor
public class LessonPointsRecord {
    private final IPointsRecordService pointsRecordService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "qa.points.queue",durable = "true"),
            exchange = @Exchange(name = LEARNING_EXCHANGE,type = ExchangeTypes.TOPIC),
            key = WRITE_REPLY

    ))
    public void addQaPointsRecord(Long userId){
    pointsRecordService.addPointsRecord(userId,5,QA);


    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "sign.points.queue",durable = "true"),
            exchange = @Exchange(name = LEARNING_EXCHANGE,type = ExchangeTypes.TOPIC),
            key =SIGN_IN
    ))
    public void addSignPointsRecord(SingMessage singMessage){
          pointsRecordService.addPointsRecord(singMessage.getUserId(),singMessage.getPoints(),SIGN);

    }
}
